<?php

class CleanForm extends CFormModel
{
	public $password;
	public $stopRebuild;

	public function rules()
	{
		return array(
			array('password', 'required'),
			array('stopRebuild', 'boolean'),
			array('password', 'authenticate', 'skipOnError' => true),
		);
	}

	public function attributeLabels()
	{
		return array(
			'stopRebuild' => '如果正在重建索引，则强制终止？',
			'password' => '确认登录密码',
		);
	}

	public function authenticate($attribute, $params)
	{
		if (!$this->hasErrors()) {
			$model = Yii::app()->user->getModel();
			if ($model->password !== $this->$attribute) {
				$this->addError('password', '输入的密码不正确。');
			}
		}
	}
}
